package com.tanhua.controller;


import com.tanhua.domain.db.User;
import com.tanhua.domain.mongo.Publish;
import com.tanhua.service.MovementsService;
import com.tanhua.util.UserHolder;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;

import java.io.IOException;

@RestController
@RequestMapping("/movements")
public class MovementsController {
    @Autowired
    private MovementsService movementsService;
    /**
     * GET/movements/recommend
     * 推荐动态
     */
    @GetMapping("/recommend")
    public ResponseEntity recommendPublish(Integer page,Integer pagesize){

        return movementsService.recommendPublish(page,pagesize);
    }

    /**
     * POST/movements
     * 发布动态
     */
    @PostMapping
    public ResponseEntity addMovements(MultipartFile[] imageContent, Publish publish,String location) throws IOException {
        publish.setLocationName(location);
        return movementsService.addMovements(imageContent,publish);
    }
    /**
     * GET/movements
     * 好友动态
     */
    @GetMapping
    public ResponseEntity friendMovements(Integer page,Integer pagesize){
        return movementsService.friendMovements(page,pagesize);
    }

    /**
     * GET/movements/all
     * 我的动态
     */
    @GetMapping("/all")
    public ResponseEntity findMyMovements(Integer page,Integer pagesize,Long userId){
        return movementsService.findMyMovements(page,pagesize,userId);
    }
    /**
     * GET/movements/:id/like
     * 点赞
     */
    @GetMapping("/{publishId}/like")
    public ResponseEntity like(@PathVariable("publishId") String publishId){
        return movementsService.like(publishId);
    }
    /**
     * GET/movements/:id/dislike
     * 取消点赞
     */
    @GetMapping("/{publishId}/dislike")
    public ResponseEntity disLike(@PathVariable("publishId") String publishId){
        return movementsService.disLike(publishId);
    }
    /**
     * GET/movements/:id/love
     * 喜欢
     */
    @GetMapping("/{publishId}/love")
    public ResponseEntity love(@PathVariable("publishId") String publishId){
        return movementsService.love(publishId);
    }
    /**
     * GET/movements/:id/unlove
     * 取消喜欢
     */
    @GetMapping("/{publishId}/unlove")
    public ResponseEntity unlove(@PathVariable("publishId") String publishId){
        return movementsService.unlove(publishId);
    }

    /**
     * GET/movements/:id
     * 动态详情
     */
    @GetMapping("{publishId}")
    public ResponseEntity oneMovement(@PathVariable("publishId")String publishId){
        return movementsService.oneMovement(publishId);

    }
    /**
     * GET/movements/visitors
     * 最近来访
     */
    @GetMapping("/visitors")
    public ResponseEntity visitors(){

        return movementsService.visitors();
    }
}
